//
//  ZHIBOCell.swift
//  FirstSwiftProduct
//
//  Created by 范泽华 on 2017/11/6.
//  Copyright © 2017年 范泽华. All rights reserved.
//

import UIKit

class ZHIBOCell: UITableViewCell {

    var imagehead : UIImageView!
    
    @IBOutlet weak var tagOne: UILabel!
    
    @IBOutlet weak var tagTwo: UILabel!
    
    @IBOutlet weak var tagThree: UILabel!
    
    @IBOutlet weak var tagFour: UILabel!
    
    @IBOutlet weak var tagFive: UILabel!
    
    @IBOutlet weak var zhibiLabel: UILabel!
    @IBOutlet weak var userImage: UIImageView!
    @IBOutlet weak var tags: UILabel!
    @IBOutlet weak var userNumber: UILabel!
    @IBOutlet weak var userName: UILabel!
    @IBOutlet weak var headImage: UIImageView!{
        get {
            return imagehead
        }
        set {
            imagehead = newValue
            imagehead.image = imagehead.image?.drawRectWithCorner(radius: 45/2, imageView: imagehead)
        }
    }
//    var <#variable name#>: <#type#> {
//        get {
//            <#statements#>
//        }
//        set {
//            <#variable name#> = newValue
//        }
//    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
//        headImage.image = headImage.image?.drawRectWithCorner(radius: 45/2, imageView: headImage)
    }
    
    public func configWithModel(model:livess) -> Void {
        
        userName.text = model.creator?.nick
        userNumber.text = model.online_users
        
        userImage.sd_setImage(with: URL.init(string: (model.creator?.portrait)!), placeholderImage: UIImage.init(named: " "), options: .retryFailed) { (image, error, cacheType, url) in
            
        }
        
        
        headImage.sd_setImage(with: URL.init(string: (model.creator?.portrait)!), placeholderImage: UIImage.init(named: " "), options: .retryFailed) { (image, error, cacheType, url) in
            self.headImage.image = self.headImage.image?.drawRectWithCorner(radius: 45/2, imageView: self.headImage)

        }
        
        
        let tagNumber = (model.extra?.label.count)
    
        
        
        if tagNumber! >= 1 {
            for i in 0...(tagNumber!-1) {
                let label:UILabel = self.viewWithTag(10086 + i) as! UILabel
                
                label.isHidden = false
                let labelst = model.extra?.label[i]
                let tag:NSString = labelst?.tab_name as! NSString
                label.text = tag as String
//                label.backgroundColor = UIColor.red
                let rect = tag.boundingRect(with: CGSize(width: CGFloat.greatestFiniteMagnitude, height:15), options: NSStringDrawingOptions(rawValue: NSStringDrawingOptions.RawValue(UInt8(NSStringDrawingOptions.usesLineFragmentOrigin.rawValue))), attributes: [NSFontAttributeName:UIFont.systemFont(ofSize: 25)], context: nil)
                label.kwidth = rect.width
                print("width:",rect.width)
                
                
            }

        }
        if tagNumber! < 5 {
            for j in tagNumber!...4{
                let label:UIView = self.viewWithTag(10086 + j)!
                label.isHidden = true
                //                label.text = ""
            }
        }
        
       
        
        
    }
    override func layoutSubviews() {
        super.layoutSubviews()
//        headImage.layer.cornerRadius = 45/2
//        headImage.layer.masksToBounds = true
//        
//        headImage.image = headImage.image?.drawRectWithCorner(radius: 45/2, imageView: headImage)
//        zhibiLabel.layer.width = 1;
        zhibiLabel.layer.borderWidth = 1
        zhibiLabel.layer.borderColor = UIColor.white.cgColor
        zhibiLabel.layer.cornerRadius = 10
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
